package cn.tx.service.impl;

import cn.tx.mapper.MemberDao;
import cn.tx.mapper.OrderDao;
import cn.tx.service.ReportService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Snake Eyes
 * @PROJECT_NAME: health_parent
 * @DESCRIPTION:
 * @USER: 11647
 * @DATE: 2021/9/11 16:47
 * @Email: 1164763541@qq.com
 */
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReport() {
        //数据查询
        /*
          reportDate:null,
         todayNewMember :0, //今天会员数
         totalMember :0,    //总会员数
         thisWeekNewMember :0,  //本周会员数
         thisMonthNewMember :0, 本月会员总数
         todayOrderNumber :0,   今天的订单数量

         */
        Map<String, Object> map = new HashMap<>();
        //格式化时间
        String date = new SimpleDateFormat("yyy-MM-dd").format(new Date());
        map.put("reportDate", date);
        //查询本周会员数据
        //分割字符串
        String[] split = date.split("-");
        //获取到天
        String Week = split[0] + "-" + split[1] + "-" + (Integer.parseInt(split[2]) - 7);
        //查询指定日期之后的会员数量
        Integer wook = memberDao.findMemberWeek(Week);
        map.put("thisWeekNewMember", wook);
        //查询本月会员数量
        String year = split[0] + "-" + split[1] + "-" + 1;
        Integer totalMember = memberDao.findSpecDateNum(year);
        map.put("thisMonthNewMember", totalMember);
        //查询总会员数
        int allMember = memberDao.findAllMember();
        map.put("totalMember", allMember);
        //设置新增会员数量
        int newMember = allMember + wook;
        map.put("thisMonthNewMember", newMember);
        //订单数据查询
        // todayVisitsNumber :0,
        map.put("todayVisitsNumber", null);
        //thisWeekOrderNumber :0,
        map.put("thisWeekOrderNumber", orderDao.findCount(date));
        //thisWeekVisitsNumber :0,
        map.put("thisWeekVisitsNumber", orderDao.findCount(Week));
        //thisMonthOrderNumber :0,
        map.put("thisMonthOrderNumber", orderDao.findCount(year));

        //thisMonthVisitsNumber :0,

        return map;
    }


}
